home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / biblio / bibtex / mac / bib.hqx / Bib Stack / stack.txt < prev   
Text File  |  1989-12-05  |  25KB  |  947 lines

  1. -- stack: in
  2. -- format: 8 (HyperCard 1)
  3. -- flags: 0x1000 (none)
  4. -- protect password hash: 0
  5. -- maximum user level: 5 (scripting)
  6. -- window: Rect(x1=0, y1=0, x2=0, y2=0)
  7. -- screen: Rect(x1=0, y1=0, x2=0, y2=0)
  8. -- card dimensions: w=0 h=0
  9. -- scroll: x=0 y=0
  10. -- background count: 17
  11. -- first background id: 2748
  12. -- card count: 33
  13. -- first card id: 3057
  14. -- list block id: 6551
  15. -- print block id: 0
  16. -- font table block id: 0
  17. -- style table block id: 0
  18. -- free block count: 3
  19. -- free size: 8672 bytes
  20. -- total size: 172032 bytes
  21. -- stack block size: 27648 bytes
  22. -- created by hypercard version: 0x01208000
  23. -- compacted by hypercard version: 0x01208000
  24. -- modified by hypercard version: 0x01208000
  25. -- opened by hypercard version: 0x01208000
  26. -- patterns[0]: 0x0000000000000000
  27. -- patterns[1]: 0x8000000008000000
  28. -- patterns[2]: 0x8800220088002200
  29. -- patterns[3]: 0x8888222288882222
  30. -- patterns[4]: 0x88AA22AA88AA22AA
  31. -- patterns[5]: 0xCCAA33AACCAA33AA
  32. -- patterns[6]: 0xEEAABBAAEEAABBAA
  33. -- patterns[7]: 0xEEBBBBEEEEBBBBEE
  34. -- patterns[8]: 0xFFBBFFEEFFBBFFEE
  35. -- patterns[9]: 0xFFBBFFFFFFBBFFFF
  36. -- patterns[10]: 0x8010022001084004
  37. -- patterns[11]: 0xFFFFFFFFFFFFFFFF
  38. -- patterns[12]: 0x8822882288228822
  39. -- patterns[13]: 0x1122448811224488
  40. -- patterns[14]: 0xC4800C6843023026
  41. -- patterns[15]: 0xB130031BD8C00C8D
  42. -- patterns[16]: 0xAA00AA00AA00AA00
  43. -- patterns[17]: 0x8822552288225522
  44. -- patterns[18]: 0x8855225588552255
  45. -- patterns[19]: 0x77DD77DD77DD77DD
  46. -- patterns[20]: 0x8000000000000000
  47. -- patterns[21]: 0xAA55AA55AA55AA55
  48. -- patterns[22]: 0x038448300C020101
  49. -- patterns[23]: 0x8244394482010101
  50. -- patterns[24]: 0x8814224188412214
  51. -- patterns[25]: 0x8080413E080814E3
  52. -- patterns[26]: 0x22048C7422179810
  53. -- patterns[27]: 0xBE808808EB088880
  54. -- patterns[28]: 0x25C8328964244C92
  55. -- patterns[29]: 0xA29C41BE2AC914EB
  56. -- patterns[30]: 0x40A00000040A0000
  57. -- patterns[31]: 0x8040200002040800
  58. -- patterns[32]: 0xAA00800088008000
  59. -- patterns[33]: 0xFF80808080808080
  60. -- patterns[34]: 0x081C22C180010204
  61. -- patterns[35]: 0xFF808080FF080808
  62. -- patterns[36]: 0xF87422478F172271
  63. -- patterns[37]: 0xBF00BFBFB0B0B0B0
  64. -- patterns[38]: 0xFF7FBE5DA2418000
  65. -- patterns[39]: 0xFAF5FAF5A050A050
  66. -- checksum: 0x0
  67. ----- HyperTalk script -----
  68. -- Some global vars
  69. --
  70. -- dupList: a return-separated list of the keys of duplicated cards
  71. -- dupCard: a comma-separated list of card numbers of the corresponding
  72. --   keys in dupList.
  73. -- searchField: the id of the field last used in a search.
  74. -- searchString: the string last used in a search.
  75. --
  76.  
  77. on openstack
  78.   -- cardList: a return-separated list of bibliography backgrounds
  79.   -- dupList is the list of duplicate keys.
  80.   -- fieldList: a comma-separated list of the fields on bibliogrpahy
  81.   --   cards. It is used to get field indexes for the find commands.
  82.   -- findList is the menu for fields to search.
  83.   -- journalList: a return-separated list of journals.
  84.   -- monthList: a return-separated list of months.
  85.   -- readStatusList: a comma-separated list of possible entries in the
  86.   --   "Read Status" field.
  87.   -- yearList: a returns-separated list of the past 5 years (descending).
  88.  
  89.   -- firstRefCard is the first card containing references.
  90.   -- recentCard is
  91.  
  92.   global cardList, dupList, fieldList, findList, journalList
  93.   global readStatusList, monthList, yearList
  94.   global firstRefCard, recentCard, termChar
  95.  
  96.   show menubar
  97.   hide message box
  98.  
  99.   -- cardList
  100.   put "Article"&return&"Book"&return&"Booklet"&return&"In Book"&return& "In Collection"&return&"In Proceedings"&return&"Manual"&return& "Masters Thesis"&return&"Misc."&return&"Ph.d Thesis"&return& "Proceedings"&return&"Tech Report"&return&"Unpublished"into cardList
  101.  
  102.   -- dupList
  103.   put "No Duplicates" into dupList
  104.  
  105.   -- fieldList
  106.   put "Card Type,Read Status,Key,"& "Author,Title,Journal,"& "Book Title,Month,Year,Chapter,"& "Pages,Editor,Organization,"& "Publisher,How Published,Address,"& "Volume,Series,Edition,Type,"& "Number,Bibliogrpahy Note,Notes,"& "Key Words,Location" into fieldList
  107.  
  108.   -- journalList
  109.   set lockScreen to true
  110.   push card
  111.   go to card "Journal Names"
  112.   --put line 1 of field "Names" into journalList
  113.   --put the number of lines of field "Names" into numLines
  114.   --repeat with linenr = 2 to numLines
  115.   --  put journalList & return & line linenr of field "Names" into journalList
  116.   --end repeat
  117.   pop card
  118.  
  119.   -- monthList
  120.   put "January"&return&"February"&return&"March"&return&"April"&return& "May"&return&"June"&return&"July"&return&"August"&return&"September"& return&"October"&return&"November"&return&"December" into monthList
  121.  
  122.   -- readStatusList
  123.   put "Read & Filed,Read & Returned,Filed & Not Read,Find It" into readStatusList
  124.  
  125.   -- yearList
  126.   put fourth word of the abbreviated date into year
  127.   put year into yearList
  128.   repeat 5 times
  129.     put year-1 into year
  130.     put yearList & return & year into yearList
  131.   end repeat
  132.  
  133.   -- findList. This list is made last so it can include other lists.
  134.   put "Repeat Search"&return&"Key"&return&"Author"&return&"Title"&return& "Read Status,"&readStatusList&return& "Notes"&return&"Key Words"&return&"Organization"&return& "All Fields"&return&"Pick Field...,"&fieldList into findList
  135.  
  136.   -- firstRefCard
  137.   put (number of first card of bkgnd "CardBeforeBibEntries")+1 into firstRefCard
  138.  
  139.   put 1 into recentCard  -- used in install and delete buttons
  140.  
  141.   --go to first card of bkgnd "Article"
  142.  
  143. end openstack
  144.  
  145. on closestack
  146.  
  147.   visual effect iris close
  148.  
  149.   get the freeSize of this stack
  150.   if it > 1024*10 then
  151.     put "Compacting stack..."
  152.     doMenu Compact Stack
  153.     put empty
  154.     hide message
  155.   end if
  156.  
  157. end closestack
  158.  
  159.  
  160. on goToCard
  161.   global cardList
  162.  
  163.   put the rect of the target into tempRect
  164.  
  165.   put item 1 of HPopupMenu(cardList,0,item 4 of tempRect-1, (item 1 of tempRect)+1) into cardNumber
  166.  
  167.   if cardNumber < 1 then exit goToCard
  168.  
  169.   put line cardNumber of cardList into bkgndName
  170.   go to background bkgndName
  171.  
  172. end goToCard
  173.  
  174. on findCard -- used to find a card
  175.   global findList, readStatusList, searchField, searchString
  176.  
  177.   put the rect of the target into tempRect
  178.   put HPopUpMenu (findList, 0,item 4 of tempRect-1, (item 1 of tempRect)+1) into itemNumber
  179.  
  180.   if itemNumber = 0 then exit findCard
  181.  
  182.   put line item 1 of itemNumber of findList into fieldName
  183.   -- If a hierarchical item was picked, the field name include all
  184.   -- the hierarchical menu, too. Get rid of it.
  185.   if "," is in fieldName put item 1 of fieldName into fieldName
  186.   put item 2 of itemNumber into subNum
  187.  
  188.   if fieldName is not "Repeat Last" then
  189.  
  190.     -- tempID holds the id of the field to look in. 0 means everywhere.
  191.  
  192.     if fieldName is "Pick Field ..." then
  193.       put subNum into tempID
  194.     else if fieldName is "All Fields" then
  195.       put 0 into tempID
  196.     else
  197.       put fieldNumber(fieldName) into tempID
  198.     end if
  199.  
  200.     if "Read Status" is in fieldName then
  201.       put item subNum of readStatusList into searchString
  202.     else
  203.       ask "Search for:" with searchString
  204.       if it is empty then exit findCard
  205.       else put it into searchString
  206.     end if
  207.  
  208.     -- record field and string information.
  209.     put tempID into searchField
  210.  
  211.   end if
  212.  
  213.   if searchField is 0 then
  214.     -- Set up the message box so all the user need do is hit return.
  215.     put "find " & searchString
  216.     hide message
  217.     find searchString
  218.   else
  219.     -- Set up the message box so all the user need do is hit return.
  220.     put "find " & searchString & " in field " & searchField
  221.     find searchString in field searchField
  222.     hide message
  223.   end if
  224.  
  225. end findCard
  226.  
  227.  
  228. on findSelection
  229.   if the locktext of the target is true then   --unlock the field if
  230.     set locktext of target to false            --it is locked.
  231.   end if
  232.  
  233.   put the optionKey into optStatus
  234.   put the commandKey into cmdStatus
  235.   if optStatus is down then
  236.     put fieldNumber("Key Words") into tempID
  237.   else if cmdStatus is down then
  238.     put fieldNumber("Key") into tempID
  239.   else
  240.     exit findSelection
  241.   end if
  242.  
  243.   if selection is not empty then  --something was selected
  244.     put selection into SelectedWord
  245.     if space is in SelectedWord then  --the user selected more than 1 word
  246.       play "boing" "Cs5"
  247.       exit findSelection            --and exit to wait for another selection
  248.     end if
  249.  
  250.     play "harpsichord" "Ct6"
  251.     find SelectedWord in field tempID
  252.     if the result is "not found" then
  253.       --play "boing" "Cs5"
  254.       play "PWscream"
  255.     else
  256.       put tempID into searchField
  257.       put SelectedWord into searchString
  258.       put "find" && quote & SelectedWord & quote && "in field" &&  SearchField
  259.       hide message
  260.     end if
  261.  
  262.   end if
  263.  
  264. end findSelection
  265.  
  266.  
  267. on checkKeys
  268.   global dupList, dupCards, firstRefCard
  269.  
  270.   push card
  271.   set cursor to 4
  272.   set lockScreen to true
  273.  
  274.   put "Sorting cards..."
  275.   sort by field "Key"
  276.  
  277.   go to card firstRefCard
  278.   put empty into prevKey
  279.   put true into firstDup
  280.   put 1 into dupCount
  281.   put "Checking for duplicate keys..."
  282.  
  283.   repeat while number of this card <> 1
  284.  
  285.     if background field Key is not empty then
  286.  
  287.       if background field Key = prevKey then
  288.  
  289.         put dupCount +1 into dupCount
  290.         put "Found " & dupCount & " duplicates of key " & prevKey
  291.  
  292.       else if dupCount > 1 then -- finished string of dups
  293.  
  294.         if firstDup then -- handle case of first item in list.
  295.           put prevKey into dupList
  296.           put  number of this card - dupCount into dupCards
  297.           put false into firstDup
  298.         else
  299.           put dupList & return & prevKey into dupList
  300.           -- Put in the number of the first dup card.
  301.           put dupCards & "," & number of this card - dupCount into dupCards
  302.         end if
  303.         put 1 into dupCount
  304.  
  305.       end if
  306.  
  307.       put background field Key into prevKey
  308.  
  309.     end if
  310.  
  311.     go to next card
  312.  
  313.   end repeat
  314.  
  315.   -- If no dups, say so.
  316.   if firstDup then
  317.     put "There were no duplicate keys."
  318.     put "No Duplicates" into dupList
  319.     put 0 into dupCards
  320.   else
  321.     put "There were duplicated keys."
  322.     play "PWscream"
  323.   end if
  324.  
  325.   pop card
  326.   set lockScreen to false
  327.  
  328. end checkKeys
  329.  
  330.  
  331. on dupKeys
  332.   global dupList, dupCards
  333.  
  334.   put the rect of the target into tempRect
  335.  
  336.   put item 1 of HPopUpMenu(dupList,0,(item 4 of tempRect)-1, (item 1 of tempRect)+1) into dupNumber
  337.  
  338.   if dupNumber is 0 then exit dupKeys
  339.  
  340.   put item dupNumber of dupCards into goCard
  341.   if goCard <> 0 then go to card goCard
  342.  
  343. end dupKeys
  344.  
  345. on makeNewCard
  346.  
  347.   put bkgnd field "card Type" into type
  348.   doMenu "New Card"
  349.   put type into background field "Card Type"
  350.   put "?" into bkgnd field "Read Status"
  351.  
  352. end makeNewCard
  353.  
  354.  
  355. on doMonth
  356.   global monthList
  357.  
  358.   put the rect of the target into tempRect
  359.  
  360.   put item 1 of HPopupMenu(monthList,0,(item 4 of tempRect)-1, (item 1 of tempRect)+1) into monthNumber
  361.  
  362.   if monthNumber < 1 then exit doMonth
  363.   else put line monthNumber of monthList into background field "Month"
  364.  
  365. end doMonth
  366.  
  367. on doYear
  368.   global yearList
  369.  
  370.   put the rect of the target into tempRect
  371.  
  372.   put item 1 of HPopupMenu(yearList,0,(item 4 of tempRect)-1, (item 1 of tempRect)+1) into yearNumber
  373.  
  374.   if yearNumber < 1 then exit doYear
  375.   else put line yearNumber of yearList into background field "Year"
  376.  
  377. end doYear
  378.  
  379.  
  380. on setReadStatus
  381.  
  382.   global readStatusList
  383.  
  384.   -- Get the current value of the field so you can check it as correctly.
  385.   put the short name of the target into statusName
  386.   if word 1 of the target is "card" then
  387.     put card field statusName into statusValue
  388.   else
  389.     put bkgnd field statusName into statusValue
  390.   end if
  391.   put 0 into checkItem
  392.   repeat with x = 1 to number of items in readStatusList
  393.     if statusValue is item x of readStatusList then
  394.       put x into checkItem
  395.       exit repeat
  396.     end if
  397.   end repeat
  398.  
  399.   -- Convert the readStatusList to one that is return-separated.
  400.   put item 1 of readStatusList into statusList
  401.   repeat with x = 2 to the number of items in readStatusList
  402.     put statusList & return & item x of readStatusList into statusList
  403.   end repeat
  404.  
  405.   put the rect of the target into tempRect
  406.  
  407.   put item 1 of HPopupMenu(statusList,checkItem,(item 2 of tempRect), (item 1 of tempRect)+1) into statusValue
  408.  
  409.   if statusValue = 0 then exit setReadStatus
  410.   else put item statusValue of readStatusList into the target
  411.  
  412. end setReadStatus
  413.  
  414.  
  415. on makeBib
  416.   global bibFileName, firstRefCard, requiredEntry, lastReqEntry
  417.   global termChar -- the character that terminates lines
  418.   --  (linefeed for unix, return for mac).
  419.  
  420.   put "Make .bib for mac"&return&"Make .bib for Unix" into bibList
  421.   put the rect of the target into tempRect
  422.  
  423.   put item 1 of HPopupMenu(bibList,0,(item 4 of tempRect)-1, (item 1 of tempRect)+1) into termChar
  424.  
  425.   -- set the termination character.
  426.   if termChar is 0 then exit makeBib
  427.   else if termChar is 1 then put return into termChar
  428.   else put lineFeed into termChar
  429.   -- Note that if you have created a handler for a new form of
  430.   -- bibliograpy output, it would be called here.
  431.  
  432.   -- See what file name the user asks for
  433.   put PutFile("Save bib file as:",bibFileName) into temp
  434.   if temp is empty then
  435.     exit makeBib
  436.   end if
  437.   put temp into bibFileName
  438.  
  439.   -- This test for a return error seems useless. I don't know how to
  440.   -- intercept it.
  441.   open file bibFileName
  442.   if the result is not empty then
  443.     answer "Couldn't open file" with "OK"
  444.     exit makeBib
  445.   end if
  446.  
  447.   set lockScreen to true
  448.   set cursor to 4
  449.   push card
  450.   put the number of cards - firstRefCard+1 into totalCardNum
  451.   go to card firstRefCard-1
  452.   repeat with cardCount = 1 to totalCardNum
  453.  
  454.     go to next card
  455.     -- Tell the user how things are going.
  456.     put "Card " & cardCount & " of " & totalCardNum
  457.  
  458.     -- Do what you should for this card type
  459.     if background field Key is not empty then
  460.  
  461.       put true into requiredEntry
  462.       put false into lastReqEntry
  463.  
  464.       if the short name of this background is "Article" then
  465.         do "ArticleBib"
  466.       else if the short name of this background is "Book" then
  467.         do "BookBib"
  468.       else if the short name of this background is "Booklet" then
  469.         do "BookletBib"
  470.       else if the short name of this background is "In Book" then
  471.         do "InBookBib"
  472.       else if the short name of this background is "In Collection" then
  473.         do "InCollectionBib"
  474.       else if the short name of this background is "In Proceedings" then
  475.         do "InProceedingsBib"
  476.       else if the short name of this background is "Manual" then
  477.         do "ManualBib"
  478.       else if the short name of this background is "Misc." then
  479.         do "MiscBib"
  480.       else if the short name of this background is "Proceedings" then
  481.         do "ProceedingsBib"
  482.       else if the short name of this background is "Tech Report" then
  483.         do "TechReportBib"
  484.       else if the short name of this background is "Masters Thesis" then
  485.         do "MSThesisBib"
  486.       else if the short name of this background is "Ph.d Thesis" then
  487.         do "PhdThesisBib"
  488.       else if the short name of this background is "Unpublished" then
  489.         do "UnpublishedBib"
  490.       end if
  491.  
  492.     end if
  493.   end repeat
  494.  
  495.   pop card
  496.   set lockScreen to false
  497.   close file bibFileName
  498.   hide message
  499.  
  500.   -- Save only the file name, not the full path.
  501.   put LastPathComponent(bibFIleName) into bibFileName
  502.  
  503. end makeBib
  504.  
  505. on DoLine -- make an entry
  506.   global requiredEntry, lastReqEntry, bibFileName, termChar
  507.   global lineName, lineField
  508.   if requiredEntry then
  509.     write tab & lineName & " = {" & field lineField & "}" to file bibFileName
  510.     if not lastReqEntry then
  511.       write "," & termChar to file bibFileName
  512.     end if
  513.   else
  514.     if field lineField is not empty
  515.     then write "," & termChar & tab & lineName & " = {" & field lineField & "}" to file bibFileName
  516.   end if
  517. end DoLine
  518. on AddressLine
  519.   global lineName, lineField
  520.   put "address" into lineName
  521.   put "address" into lineField
  522.   do "DoLine"
  523. end AddressLine
  524. on AuthorLine
  525.   global lineName, lineField
  526.   put "author" into lineName
  527.   put "author" into lineField
  528.   do "DoLine"
  529. end AuthorLine
  530. on BooktitleLine
  531.   global lineName, lineField
  532.   put "booktitle" into lineName
  533.   put "book title" into lineField
  534.   do "DoLine"
  535. end BooktitleLine
  536. on ChapterLine
  537.   global lineName, lineField
  538.   put "chapter" into lineName
  539.   put "chapter" into lineField
  540.   do "DoLine"
  541. end ChapterLine
  542. on EditionLine
  543.   global lineName, lineField
  544.   put "edition" into lineName
  545.   put "edition" into lineField
  546.   do "DoLine"
  547. end EditionLine
  548. on EditorLine
  549.   global lineName, lineField
  550.   put "editor" into lineName
  551.   put "editor" into lineField
  552.   do "DoLine"
  553. end EditorLine
  554. on HowpublishedLine
  555.   global lineName, lineField
  556.   put "howpublished" into lineName
  557.   put "how published" into lineField
  558.   do "DoLine"
  559. end HowpublishedLine
  560. on InstitutionLine
  561.   global lineName, lineField
  562.   put "institution" into lineName
  563.   put "organization" into lineField
  564.   do "DoLine"
  565. end InstitutionLine
  566. on JournalLine
  567.   global lineName, lineField
  568.   put "journal" into lineName
  569.   put "journal" into lineField
  570.   do "DoLine"
  571. end JournalLine
  572. on KeyLine
  573.   global termChar, bibFileName
  574.   write "{" & field Key & "," & termChar to file bibFileName
  575. end KeyLine
  576. on LastLine
  577.   global termChar, bibFileName
  578.   write " }" & termChar to file bibFileName
  579. end LastLine
  580. on MonthLine
  581.   global lineName, lineField
  582.   put "month" into lineName
  583.   put "month" into lineField
  584.   do "DoLine"
  585. end MonthLine
  586. on NumberLine
  587.   global lineName, lineField
  588.   put "number" into lineName
  589.   put "number" into lineField
  590.   do "DoLine"
  591. end NumberLine
  592. on OrganizationLine
  593.   global lineName, lineField
  594.   put "organization" into lineName
  595.   put "organization" into lineField
  596.   do "DoLine"
  597. end OrganizationLine
  598. on PagesLine
  599.   global lineName, lineField
  600.   put "pages" into lineName
  601.   put "pages" into lineField
  602.   do "DoLine"
  603. end PagesLine
  604. on PublisherLine
  605.   global lineName, lineField
  606.   put "publisher" into lineName
  607.   put "publisher" into lineField
  608.   do "DoLine"
  609. end PublisherLine
  610. on SchoolLine
  611.   global lineName, lineField
  612.   put "school" into lineName
  613.   put "organization" into lineField
  614.   do "DoLine"
  615. end SchoolLine
  616. on SeriesLine
  617.   global lineName, lineField
  618.   put "series" into lineName
  619.   put "series" into lineField
  620.   do "DoLine"
  621. end SeriesLine
  622. on TitleLine
  623.   global lineName, lineField
  624.   put "title" into lineName
  625.   put "title" into lineField
  626.   do "DoLine"
  627. end TitleLine
  628. on TypeLine
  629.   global lineName, lineField
  630.   put "type" into lineName
  631.   put "type" into lineField
  632.   do "DoLine"
  633. end TypeLine
  634. on bibliographyNoteLine
  635.   global lineName, lineField
  636.   put "note" into lineName
  637.   put "bibliography Note" into lineField
  638.   do "DoLine"
  639. end bibliographyNoteLine
  640. on VolumeLine
  641.   global lineName, lineField
  642.   put "volume" into lineName
  643.   put "volume" into lineField
  644.   do "DoLine"
  645. end VolumeLine
  646. on YearLine
  647.   global lineName, lineField
  648.   put "year" into lineName
  649.   put "year" into lineField
  650.   do "DoLine"
  651. end YearLine
  652.  
  653. on ArticleBib
  654.   global bibFileName, requiredEntry, lastReqEntry
  655.   write "@Article" to file bibFileName
  656.   do "KeyLine"
  657.   do "AuthorLine"
  658.   do "TitleLine"
  659.   do "JournalLine"
  660.   put true into lastReqEntry
  661.   do "YearLine"
  662.   put false into requiredEntry
  663.   do "VolumeLine"
  664.   do "NumberLine"
  665.   do "PagesLine"
  666.   do "MonthLine"
  667.   do "LastLine"
  668. end ArticleBib
  669.  
  670. on BookBib
  671.   global bibFileName, requiredEntry, lastReqEntry
  672.   write "@BOOK" to file bibFileName
  673.   do "KeyLine"
  674.   do "AuthorLine"
  675.   do "TitleLine"
  676.   do "PublisherLine"
  677.   put true into lastReqEntry
  678.   do "YearLine"
  679.   put false into requiredEntry
  680.   do "VolumeLine"
  681.   do "SeriesLine"
  682.   do "AddressLine"
  683.   do "EditionLine"
  684.   do "MonthLine"
  685.   do "LastLine"
  686. end BookBib
  687.  
  688. on BookletBib
  689.   global bibFileName, requiredEntry, lastReqEntry
  690.   write "@Booklet" to file bibFileName
  691.   do "KeyLine"
  692.   put true into lastReqEntry
  693.   do "TitleLine"
  694.   put false into requiredEntry
  695.   do "AuthorLine"
  696.   do "HowpublishedLine"
  697.   do "AddressLine"
  698.   do "MonthLine"
  699.   do "YearLine"
  700.   do" LastLine"
  701. end BookletBib
  702.  
  703. on InProceedingsBib
  704.   global requiredEntry, bibFileName, lastReqEntry
  705.   write "@InProceedings" to file bibFileName
  706.   do "KeyLine"
  707.   do "AuthorLine"
  708.   do "TitleLine"
  709.   do "BooktitleLine"
  710.   put true into lastReqEntry
  711.   do "YearLIne"
  712.   put false into requiredEntry
  713.   do "EditorLine"
  714.   do "PagesLine"
  715.   do "OrganizationLine"
  716.   do "PublisherLine"
  717.   do "AddressLine"
  718.   do "MonthLine"
  719.   do "LastLine"
  720. end InProceedingsBib
  721.  
  722. on InBookBib
  723.   global requiredEntry, bibFileName, lastReqEntry
  724.   write "@InBook" to file bibFileName
  725.   do "KeyLine"
  726.   do "AuthorLine"
  727.   do "TitleLIne"
  728.   do "PublisherLine"
  729.   put true into lastReqEntry
  730.   do "YearLine"
  731.   put false into requiredEntry
  732.   do "ChapterLine"        -- chapter and pages are after the required
  733.   do "PagesLine"          -- entries becuase only one is required.
  734.   do "VolumeLine"
  735.   do "SeriesLine"
  736.   do "AddressLIne"
  737.   do "EditionLine"
  738.   do "MonthLIne"
  739.   do "LastLine"
  740. end InBookBib
  741.  
  742. on InCollectionBib
  743.   global requiredEntry, bibFileName, lastReqEntry
  744.   write "@InCollection" to file bibFileName
  745.   do "KeyLine"
  746.   do "AuthorLine"
  747.   do "TitleLIne"
  748.   do "BooktitleLine"
  749.   do "PublisherLine"
  750.   put true into lastReqEntry
  751.   do "YearLine"
  752.   put false into requiredEntry
  753.   do "EditorLIne"
  754.   do "ChapterLine"
  755.   do "PagesLine"
  756.   do "AddressLine"
  757.   do "MonthLine"
  758.   do "LastLine"
  759. end InCollectionBib
  760.  
  761. on ManualBib
  762.   global requiredEntry, bibFileName, lastReqEntry
  763.   write "@Manual" to file bibFileName
  764.   do "KeyLine"
  765.   put true into lastReqEntry
  766.   do "TitleLine"
  767.   put false into requiredEntry
  768.   do "AuthorLine"
  769.   do "OrganizationLine"
  770.   do "AddressLine"
  771.   do "EditionLine"
  772.   do "MonthLine"
  773.   do "YearLine"
  774.   do "LastLine"
  775. end ManualBib
  776.  
  777. on MiscBib
  778.   global requiredEntry, lastReqEntry, bibFileName, termChar
  779.   write "@Misc" to file bibFileName
  780.   put true into lastReqEntry
  781.   do "KeyLine"
  782.   if field author is not empty then
  783.     do "AuthorLine"
  784.     put false into requiredEntry
  785.   end if
  786.   if field title is not empty then
  787.     do "TitleLine"
  788.     put false into requiredEntry
  789.   end if
  790.   if field "how published" is not empty then
  791.     do "HowpublishedLine"
  792.     put false into requiredEntry
  793.   end if
  794.   if field month is not empty then
  795.     do "MonthLine"
  796.     put false into requiredEntry
  797.   end if
  798.   if field year is not empty then
  799.     do "YearLine"
  800.   end if
  801.   do "LastLine"
  802. end MiscBib
  803.  
  804. on ProceedingsBib
  805.   global requiredEntry, bibFileName, lastReqEntry
  806.   write "@Proceedings" to file bibFileName
  807.   do "KeyLine"
  808.   do "TitleLine"
  809.   put true into lastReqEntry
  810.   do "YearLine"
  811.   put false into RequiredEntry
  812.   do "EditorLine"
  813.   do "PublisherLine"
  814.   do "OrganizationLine"
  815.   do "AddressLIne"
  816.   do "MonthLine"
  817.   do "LastLine"
  818. end ProceedingsBib
  819.  
  820. on TechReportBib
  821.   global requiredEntry, bibFileName, lastReqEntry
  822.   write "@TechReport" to file bibFileName
  823.   do "KeyLine"
  824.   do "AuthorLine"
  825.   do "TitleLine"
  826.   do "InstitutionLine"
  827.   put true into lastReqEntry
  828.   do "YearLine"
  829.   put false into requiredEntry
  830.   do "TypeLine"
  831.   do "NumberLine"
  832.   do "AddressLine"
  833.   do "MonthLine"
  834.   do "LastLine"
  835. end TechReportBib
  836.  
  837. on MSThesisBib
  838.   -- use phdthesis for both masters and phd theses. I don't know if
  839.   -- these really should differ when printed.
  840.   global requiredEntry, bibFileName, lastReqEntry
  841.   write "@mastersthesis" to file bibFileName
  842.   do "KeyLine"
  843.   do "AuthorLine"
  844.   do "TitleLine"
  845.   do "SchoolLine"
  846.   put true into lastReqEntry
  847.   do "YearLine"
  848.   put false into requiredEntry
  849.   do "AddressLine"
  850.   do "MonthLIne"
  851.   do "LastLine"
  852. end MSThesisBib
  853.  
  854. on PhdThesisBib
  855.   -- use phdthesis for both masters and phd theses. I don't know if
  856.   -- these really should differ when printed.
  857.   global requiredEntry, bibFileName, lastReqEntry
  858.   write "@phdthesis" to file bibFileName
  859.   do "KeyLine"
  860.   do "AuthorLine"
  861.   do "TitleLine"
  862.   do "SchoolLine"
  863.   put true into lastReqEntry
  864.   do "YearLine"
  865.   put false into requiredEntry
  866.   do "AddressLine"
  867.   do "MonthLIne"
  868.   do "LastLine"
  869. end PhdThesisBib
  870.  
  871. on UnpublishedBib
  872.   global requiredEntry, bibFileName, lastReqEntry
  873.   write "@Unpublished" to file bibFileName
  874.   do "KeyLine"
  875.   do "AuthorLine"
  876.   do "TitleLIne"
  877.   put true into lastReqEntry
  878.   do "bibliographyNoteLine"
  879.   put false into requiredEntry
  880.   do "MonthLine"
  881.   do "YearLine"
  882.   do "LastLine"
  883. end UnpublishedBib
  884.  
  885.  
  886.  
  887. --
  888. -- LastPathComponent -- given a file pathname, returns the last
  889. -- component i.e. whatever comes after the last colon, if anything.
  890. -- From Dewi Williams
  891. --
  892. function LastPathComponent name
  893. -- scan backwards for the last colon.
  894. repeat with i = the length of name down to 1
  895.   if character i of name is ":" then exit repeat
  896. end repeat
  897.  
  898. if i is 1 then
  899.   -- Name was of the form ":thing" or "thing". Check for leading
  900.   -- colon, and adjust if necessary. Done for generality.
  901.   if first character of name is ":" then
  902.     put 2 into i
  903.   end if
  904. else
  905.   add 1 to i -- skip the colon
  906. end if
  907.  
  908. -- Name was of the form "Thing:otherthing". Return "otherThing".
  909. put empty into lastpath
  910. repeat with j = i to the length of name
  911.   put character j of name after lastpath
  912. end repeat
  913. return lastpath
  914. end LastPathComponent
  915.  
  916.  
  917. function readField fileName
  918. -- this reads from a file until it hits a tab, and returns the field
  919. -- without the tab.
  920. put "" into temp
  921. read from file fileName until tab
  922. put it into tempLong
  923. put length(tempLong)-1 into tempLen
  924. repeat with x = 1 to tempLen
  925.   put char x of tempLong into char x of temp
  926. end repeat
  927. return temp
  928. end readField
  929.  
  930.  
  931. function fieldNumber fieldName
  932. -- Given a field name, return the number of the field. Return 0 if
  933. -- the field name does not exist.
  934. global fieldList
  935. put the number of items in fieldList into fieldListLen
  936. repeat with x = 1 to fieldListLen
  937.   if item x of fieldList is fieldName then return x
  938. end repeat
  939. return 0
  940. end fieldNumber
  941.  
  942. on complainSound
  943.   -- Make a complaining sound.
  944.   play "PWscream"
  945. end complainSound
  946.  
  947.